package net.guerlab.credits.usercredits.dqi.impl;

import org.apache.commons.lang3.StringUtils;

import net.guerlab.credits.creditsoption.exception.CreditIdIsNullError;
import net.guerlab.credits.usercredits.dqi.UserCreditsDQI;
import net.guerlab.credits.usercredits.entity.UserCredits;
import net.guerlab.credits.usercredits.exception.UserCreditsIsNullError;
import net.guerlab.credits.usercredits.exception.UserIdIsNullError;

/**
 * 用户积分数据查询接口简单实现
 * 
 * @author guer
 *
 */
public class UserCreditsDQIImpl extends UserCreditsDQI {

    private static final long serialVersionUID = 1L;

    @Override
    public void saveCheck(UserCredits entity) {
        check(entity);
    }

    @Override
    public void updateCheck(UserCredits entity) {
        check(entity);
    }

    @Override
    public void deleteCheck(UserCredits entity) {
        check(entity);
    }

    private static void check(UserCredits entity) {
        if (entity == null) {
            throw new UserCreditsIsNullError();
        }

        if (StringUtils.isBlank(entity.getUserId())) {
            throw new UserIdIsNullError();
        }

        if (entity.getCreditId() == null || entity.getCreditId() <= 0) {
            throw new CreditIdIsNullError();
        }
    }

}
